<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Login</title>
</head>
<body>

	<form id="form1" action="/app/login/" method="post">
{#		{% csrf_token %}#}
		<div><input type="text" name="user" placeholder="用户名"/></div>
		<div><input type="password" name="pwd" placeholder="密码"/></div>
		<div><input type="submit" value="提交" /></div>
		<div><input id="btn" type="button" value="ajax提交按钮测试" /> </div>
	</form>

	<script src="/static/jquery.min.js" ></script>
	<script src="/static/jquery.cookie.js" ></script>

	<script>
		//全局配置csrf验证
		$.ajaxSetup({
			beforeSend:function(xhr,settings){
				xhr.setRequestHeader('X-CSRFtoken',$.cookie('csrftoken'));
			}
		})

		$('#btn').click(function () {
			$.ajax({
				url:'/app/login/',
				type:'POST',
				data:$('#form1').serialize(),
				success:function (result) {
					var result = JSON.parse(result)
					if(result['status']){
						location.href='/app/index'
					}else{
						location.reload()
					}
				}
			})
		})


	</script>
</body>
</html>